home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Plus 2002 #3
/
Amiga Plus CD - 2002 - No. 03.iso
/
AmiSoft
/
Mus
/
Play
/
Mhm_mayhem.lha
/
mhm-mAYhem_deli
/
hardAY
/
hardAY_test.c
< prev
next >
Wrap
C/C++ Source or Header
|
2002-08-17
|
5KB
|
283 lines
#include <exec/memory.h>
#include <clib/dos_protos.h>
#include <clib/exec_protos.h>
#include <clib/timer_protos.h>
#include <pragmas/exec_sysbase_pragmas.h>
#include <pragmas/timer_pragmas.h>
#include <pragmas/dos_pragmas.h>
#include <utility/tagitem.h>
#include <dos/dos.h>
#include <dos/dosextens.h>
#include <dos/dostags.h>
#include "hardAY.h"
struct Library * DOSBase, * SysBase;
BPTR inp,outp;
// timer related
struct Library * TimerBase;
struct MsgPort * tmrport;
struct timerequest * tmr_rq;
ULONG timer_Init(void);
void timer_Free(void);
void timer_Wait(ULONG,ULONG);
void timer_Start(ULONG,ULONG);
void timer_BadWaitEnd(void);
void timer_WaitEnd(void);
void timer_Prep(ULONG,ULONG);
void test_AY(void);
__saveds main()
{
ULONG timer_res=0;
SysBase = *((struct Library **)4L);
if(DOSBase = OpenLibrary("dos.library",36))
{
inp=Input();outp=Output();
timer_res=timer_Init();
if( timer_res )
{
test_AY();
}
if( timer_res ) timer_Free();
CloseLibrary(DOSBase);
}
}
void test_AY(void)
{
ULONG Success;
UBYTE lefttone[] = { 1,1, 0,00, 7,0xFE, 8,15};
UBYTE righttone[] = { 5,1, 4,10, 7,0xFB, 10,15};
UBYTE centertone[] = { 3,1, 2,20, 7,0xFD, 9,15};
UBYTE lownoise[] = { 6,31, 7,0xEF, 9,15 };
UBYTE highnoise[] = { 6,1, 7,0xEF, 9,15 };
UBYTE lsenv[] = { 3,1, 2,60, 7,0xFD, 9,16, 12,5, 11,0, 13,0x0A };
UBYTE hsenv[] = { 3,1, 2,60, 7,0xFD, 9,16, 12,0, 11,10, 13,0x0A };
UBYTE hsenvl[] = { 1,1, 0,60, 7,0xFE, 8,16, 12,0, 11,10, 13,0x0A };
UBYTE hsenvr[] = { 5,1, 4,60, 7,0xFB, 10,16, 12,0, 11,10, 13,0x0A };
UBYTE puenv[] = { 7,0xFF, 9,16, 12,0, 11,30, 13,0x0A };
Success=hardAY_On();
if( !Success )
{
Printf("Now AY is shut up\n");
hardAY_Shut();
Printf("Frequency is set to 1.750000 MHz\n");
hardAY_SetFreq(1750000);
timer_Wait(1,0);
Printf("\nNow AY is generating tone:\n Left\n");
hardAY_WrRegList(lefttone,4);
timer_Wait(2,0);
hardAY_Shut();
timer_Wait(1,0);
Printf(" Right\n");
hardAY_WrRegList(righttone,4);
timer_Wait(2,0);
hardAY_Shut();
timer_Wait(1,0);
Printf(" Center\n");
hardAY_WrRegList(centertone,4);
timer_Wait(2,0);
hardAY_Shut();
timer_Wait(1,0);
Printf("\nNow AY is generating noise:\n Low-frequency\n");
hardAY_WrRegList(lownoise,3);
timer_Wait(2,0);
hardAY_Shut();
timer_Wait(1,0);
Printf(" High-frequency\n");
hardAY_WrRegList(highnoise,3);
timer_Wait(2,0);
hardAY_Shut();
timer_Wait(1,0);
Printf("\nNow AY is generating envelope:\n Low-speed\n");
hardAY_WrRegList(lsenv,7);
timer_Wait(5,0);
hardAY_Shut();
timer_Wait(1,0);
Printf(" High-speed\n");
hardAY_WrRegList(hsenv,7);
timer_Wait(2,0);
hardAY_Shut();
timer_Wait(1,0);
hardAY_WrRegList(hsenvl,7);
timer_Wait(2,0);
hardAY_Shut();
timer_Wait(1,0);
hardAY_WrRegList(hsenvr,7);
timer_Wait(2,0);
hardAY_Shut();
timer_Wait(1,0);
Printf(" Without tone\n");
hardAY_WrRegList(puenv,5);
timer_Wait(2,0);
hardAY_Shut();
timer_Wait(1,0);
Printf("\nNow frequency of AY will be changed:\n 1.750000 MHz\n");
hardAY_SetFreq(1750000);
hardAY_WrRegList(centertone,4);
timer_Wait(3,0);
Printf(" 1.773448 MHz\n");
hardAY_SetFreq(1773448);
timer_Wait(3,0);
Printf(" 1.000000 MHz\n");
hardAY_SetFreq(1000000);
timer_Wait(3,0);
Printf(" 2.000000 MHz\n");
hardAY_SetFreq(2000000);
timer_Wait(3,0);
hardAY_Shut();
timer_Wait(1,0);
Printf("\nTests passed... Have you heard anything? %%)\n\n");
hardAY_Off();
}
else
{
if( Success==2 )
{
Printf("Can't allocate parallel port!\n");
}
else if( Success==1 )
{
Printf("No connected AY found! Check hardware.\n");
}
else
{
Printf("Unknown error %\\n");
}
}
}
/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- **
** functions for working with timer **
** -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
ULONG timer_Init(void)
{
tmrport=CreateMsgPort();
if( !tmrport )
{
Printf("aprg: Can't create msgport!\n");
return 0;
}
tmr_rq=(struct timerequest *)CreateIORequest(tmrport,sizeof(struct timerequest));
if( !tmr_rq )
{
Printf("aprg: Can't create IORequest!\n");
DeleteMsgPort(tmrport);
return 0;
}
if( OpenDevice(TIMERNAME,UNIT_MICROHZ,(struct IORequest *)tmr_rq,0) )
{
Printf("aprg: Can't open %s!\n",TIMERNAME);
DeleteIORequest(tmr_rq);
DeleteMsgPort(tmrport);
return 0;
}
TimerBase=(struct Library *)tmr_rq->tr_node.io_Device;
return 1;
}
void timer_Free(void)
{
CloseDevice((struct IORequest *)tmr_rq);
DeleteIORequest(tmr_rq);
DeleteMsgPort(tmrport);
}
void timer_Wait(ULONG secs,ULONG usecs)
{
timer_Prep(secs,usecs);
DoIO( (struct IORequest *)tmr_rq );
}
void timer_Start(ULONG secs,ULONG usecs)
{
timer_Prep(secs,usecs);
SendIO( (struct IORequest *)tmr_rq );
}
void timer_BadWaitEnd(void)
// timer_WaitEnd() MUST be used after this function
{
ULONG sigmask;
sigmask=1<<(tmrport->mp_SigBit);
while( !(SetSignal(0L,sigmask)&sigmask) );
}
void timer_WaitEnd(void)
{
WaitIO( (struct IORequest *)tmr_rq );
}
void timer_Prep(ULONG secs,ULONG usecs)
{
ULONG s,us;
s=secs;us=usecs;
if( us>999999 )
{
s+=us/1000000;us%=1000000;
}
tmr_rq->tr_node.io_Command = TR_ADDREQUEST;
tmr_rq->tr_time.tv_secs = s;
tmr_rq->tr_time.tv_micro = us;
}